package example;
import facecat.FaceCatScript;
import facecat.topin.core.*;
import facecat.topin.xml.*;
import facecat.topin.tab.*;
import facecat.topin.btn.*;
import org.w3c.dom.Node;

/*
* 绘图示例
*/
public class PaintExample extends FCUIXml implements FCPaintEventCallBack
{
    /*
    * 加载Xml
    * @param fileName 文件名
    * @param view 视图名称
    */
   public void loadXml(String fileName, FCView view)
   {
       setScript(new FaceCatScript(this));
       super.loadXml(fileName, view);
       FCTabPage tabPage1 = getTabPage("TabPage");
        FCTabPage tabPage2 = getTabPage("TabPage2");
        FCTabPage tabPage3 = getTabPage("TabPage3");
        FCTabPage tabPage4 = getTabPage("TabPage4");
        FCTabPage tabPage5 = getTabPage("TabPage5");
        FCTabPage tabPage6 = getTabPage("TabPage6");
        tabPage1.addEvent(this, FCEventID.Paint, this);
        tabPage2.addEvent(this, FCEventID.Paint, this);
        tabPage3.addEvent(this, FCEventID.Paint, this);
        tabPage4.addEvent(this, FCEventID.Paint, this);
        tabPage5.addEvent(this, FCEventID.Paint, this);
        tabPage6.addEvent(this, FCEventID.Paint, this);
   }
   
   /*
   * 绘图方法
   */
   public boolean callPaintEvent(String eventName, Object sender, FCPaint paint, FCRect clipRect, Object invoke)
    {
        FCView view = (FCView)sender;
        String name = view.getName();
        if (name.equals("TabPage"))
        {
            paint.drawLine(FCColor.rgb(255, 0, 0), 1, 0, 100, 100, 300, 300);
            paint.drawLine(FCColor.rgb(255, 0, 255), 5, 2, 100, 300, 300, 100);
        }
        else if (name.equals("TabPage2"))
        {
            paint.drawRect(FCColor.rgb(0, 255, 0), 1, 0, 100, 100, 200, 200);
            paint.fillRect(FCColor.rgb(0, 0, 255), 250, 250, 350, 350);
        }
        else if (name.equals("TabPage3"))
        {
            paint.drawEllipse(FCColor.rgb(0, 255, 255), 1, 0, 100, 100, 200, 200);
            paint.fillEllipse(FCColor.rgb(255, 0, 255), 250, 250, 350, 350);
        }
        else if (name.equals("TabPage4"))
        {
            String text = "FaceCat";
            FCFont tFont = new FCFont("Default", 30);
            FCSize tSize = paint.textSize(text, tFont);
            FCRect tRect = new FCRect(100, 100, 100 + tSize.cx, 100 + tSize.cy);
            paint.drawText(text, FCColor.rgb(255, 0, 0), tFont, tRect);
        }
        else if (name.equals("TabPage5"))
        {
            FCPoint[] points = new FCPoint[5];
            points[0] = new FCPoint(100, 100);
            points[1] = new FCPoint(150, 120);
            points[2] = new FCPoint(130, 200);
            points[3] = new FCPoint(200, 200);
            points[4] = new FCPoint(250, 220);
            paint.drawPolyline(FCColor.rgb(255, 0, 0), 1, 0, points);
        }
        else if (name.equals("TabPage6"))
        {
            FCPoint[] points = new FCPoint[4];
            points[0] = new FCPoint(100, 100);
            points[1] = new FCPoint(150, 120);
            points[2] = new FCPoint(200, 200);
            points[3] = new FCPoint(150, 200);
            paint.fillPolygon(FCColor.rgb(0, 0, 255), points);
        }
        return false;
    }
}